package com.sharemarking.application.common.service;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import com.sharemarking.application.common.entity.Department;
import com.sharemarking.application.common.repository.DepartmentRepo;

@Service
public class DepartmentService {
	
	@Autowired
	private DepartmentRepo dr;
	
	public Iterable<Department> getAllDepartment(){
		return dr.findAll(new Specification<Department>() {
			
			@Override
			public Predicate toPredicate(Root<Department> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
				return cb.notEqual(root.get("name").as(String.class), "ADMINISTRATOR");
			}
		});
			
	}
}
